<template>
  <div>
    <h1>{{ msg }}</h1>

    <School :getSchoolName="getSchoolName"></School>

    <!-- <Student @atguigu="demo"></Student> -->
    <!-- 给组件studnet的vc身上绑定事件atguigu -->

    <Student ref="student"></Student>
  </div>
</template>

<script>
import School from "./components/School.vue";
import Student from "./components/Student.vue";

export default {
  name: "App",
  components: { School, Student },
  data() {
    return {
      msg: "HELLO",
    };
  },
  methods: {
    getSchoolName(name) {
      console.log("App收到学校名", name);
    },
    demo(name) {
      console.log("dome被调用了");
      console.log("学生名是：", name);
    },
  },
  mounted() {
    this.$refs.student.$on("atguigu", this.demo);
    // $on 绑定事件，$once 绑定一次性事件
  },
};
</script>

<style>
</style>
